﻿Imports System.Data.OleDb
Public Class Editprofile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim newFileName As String
        newFileName = Guid.NewGuid().ToString() & getSuffix(fup_Portrait.filename)
        If fup_Portrait.HasFile Then
            fup_Portrait.SaveAs(Server.MapPath("Dealpictures") & "/" & newFileName)
        End If

        Dim userDOB As DateTime = New DateTime(CInt(ddl_year.SelectedValue), CInt(ddl_month.SelectedValue), CInt(ddl_day.SelectedValue))

        Dim sql As String = "UPDATE UserProfile SET Firstname=@f1,Lastname=@f2,Portrait=@f3,Dateofbirth=@f4,Gender=@f5 WHERE Dinerid=@f6 "
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("DealsDbConnection").ConnectionString)
        conn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@f1", tb_fname.Text)
        cmd.Parameters.AddWithValue("@f2", tb_lname.Text)
        cmd.Parameters.AddWithValue("@f5", tb_gender.Text)
        cmd.Parameters.AddWithValue("@f6", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f3", "Dealpictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f4", userDOB.Date)

        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()

    End Sub

    Function getSuffix(ByVal fn As String)
        Dim fileParts = fn.Split(".")
        Dim suffix = fileParts(fileParts.Length - 1)
        Return "." & suffix
    End Function
End Class